package controller

import (
	commom "../Common"
	db "../dataBase"
	pb "../protobuf"
	"golang.org/x/net/context"
	"gopkg.in/mgo.v2/bson"
)

func (s Service) AddUserKnowledge(ctx context.Context, in *pb.Userknowledgepoint) (*pb.AddUserKnowledgeReply, error) {
	// 接口实现
	var dat=commom.Userknowledgepoint(in)
	selector := bson.M{"syllabusknowledgepointid": dat.SyllabusKnowledgePointID,"userid":dat.Userid,"isright":dat.IsRight}
	data := bson.M{"$set": dat}
	err:=db.Upsert("db","Userknowledgepoint",selector,data)
	//_=db.FindOne("db","Userknowledgepoint",nil,selector,&d)
	if(err!=nil){
		return &pb.AddUserKnowledgeReply{Error:true,ErrorMsg:err.Error()} ,nil
	}
	return &pb.AddUserKnowledgeReply{} ,nil
}